package ro.prjmanager.web;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import ro.prjmanager.core.list.TabelOutJson;
import ro.prjmanager.core.list.RowJson;

public class AnnotatedServlet extends HttpServlet {



    private String pag1="{\n" +
                "page: 1,\n" +
                "total: 2,\n" +
                "rows: [\n" +
                "{id:'ZW',cell:['ZW','ZIMBABWE','Zimbabwe','ZWE','716']},\n" +
                "{id:'ZM',cell:['ZM','ZAMBIA','Zambia','ZMB','894']},\n" +
                "{id:'YE',cell:['YE','YEMEN','Yemen','YEM','887']},\n" +
                "{id:'EH',cell:['EH','WESTERN SAHARA','Western Sahara','ESH','732']},\n" +
                "{id:'WF',cell:['WF','WALLIS AND FUTUNA','Wallis and Futuna','WLF','876']},\n" +
                "{id:'VI',cell:['VI','VIRGIN ISLANDS, U.S.','Virgin Islands, U.s.','VIR','850']},\n" +
                "{id:'VG',cell:['VG','VIRGIN ISLANDS, BRITISH','Virgin Islands, British','VGB','92']},\n" +
                "{id:'VN',cell:['VN','VIET NAM','Viet Nam','VNM','704']},\n" +
                "{id:'VE',cell:['VE','VENEZUELA','Venezuela','VEN','862']},\n" +
                "{id:'VU',cell:['VU','VANUATU','Vanuatu','VUT','548']}]\n" +
                "}";

    private String pag2="{\n" +
                "page: 1,\n" +
                "total: 20,\n" +
                "rows: [\n" +
                "{id:'ZW',cell:['ZW','ZIMBABWE','Zimbabwe','ZWE','716']},\n" +
                "{id:'ZM',cell:['ZM','ZAMBIA','Zambia','ZMB','894']},\n" +
                "{id:'YE',cell:['YE','YEMEN','Yemen','YEM','887']},\n" +
                "{id:'EH',cell:['EH','WESTERN SAHARA','Western Sahara','ESH','732']},\n" +
                "{id:'WF',cell:['WF','WALLIS AND FUTUNA','Wallis and Futuna','WLF','876']},\n" +
                "{id:'VI',cell:['VI','VIRGIN ISLANDS, U.S.','Virgin Islands, U.s.','VIR','850']},\n" +
                "{id:'VG',cell:['VG','VIRGIN ISLANDS, BRITISH','Virgin Islands, British','VGB','92']},\n" +
                "{id:'VN',cell:['VN','VIET NAM','Viet Nam','VNM','704']},\n" +
                "{id:'VE',cell:['VE','VENEZUELA','Venezuela','VEN','862']},\n" +
                "{id:'VU',cell:['VU','VANUATU','Vanuatu','VUT','548']}]\n" +

                "}";





    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        RowJson row=new RowJson(5);

        row.setCellByNo(0,"ZW");
        row.setCellByNo(1,"ZIMBABWE");
        row.setCellByNo(2,"Zimbabwe");
        row.setCellByNo(3,"ZWE");
        row.setCellByNo(4,"716");
        row.setId("ZW");

        TabelOutJson tabelOutJson=new TabelOutJson(10,1,1,1,10);
        tabelOutJson.setPage(1);
        tabelOutJson.setTotal(25);
        tabelOutJson.setRowByNo(0,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(1,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(2,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(3,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(4,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(5,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(6,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(7,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(8,row);

        row=new RowJson(5);
        row.setCellByNo(0,"ZM");
        row.setCellByNo(1,"ZAMBIA");
        row.setCellByNo(2,"Zambia");
        row.setCellByNo(3,"ZMB");
        row.setCellByNo(4,"894");
        row.setId("ZM");
        tabelOutJson.setRowByNo(9,row);


        response.setContentType("text/plain");
        ServletOutputStream out = response.getOutputStream();

        out.println(tabelOutJson.toJson());
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
        Object business=  context.getBean("userBusiness");


        doGet(request, response);
    }
  
    
   



   
}

